package cn.smbms.service.role;

import java.sql.Connection;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import cn.smbms.dao.BaseDao;
import cn.smbms.dao.provider.ProviderMapper;
import cn.smbms.dao.role.RoleDao;
import cn.smbms.dao.role.RoleDaoImpl;
import cn.smbms.dao.role.RoleMapper;
import cn.smbms.pojo.Role;
import cn.smbms.tools.MyBatisUtil;

public class RoleServiceImpl implements RoleService{
	
	private RoleDao roleDao;
	
	public RoleServiceImpl(){
		roleDao = new RoleDaoImpl();
	}
	
	@Override
	public List<Role> getRoleList() {
		// TODO Auto-generated method stub
		/*Connection connection = null;
		List<Role> roleList = null;
		try {
			connection = BaseDao.getConnection();
			roleList = roleDao.getRoleList(connection);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			BaseDao.closeResource(connection, null, null);
		}
		return roleList;*/
		SqlSession session = null;	
		List<Role> roleList = null;	
		int index = 0;
		try {
			session = MyBatisUtil.createSqlSession();	
			roleList = session.getMapper(RoleMapper.class).getRoleList();
			System.out.println("index : " + index);
			session.commit();
			
		} catch (Exception e) {
			e.printStackTrace();
			session.rollback();
		} finally {
			MyBatisUtil.closeSqlSession(session);
		}
		return roleList;
	}
	
}
